<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="请输入姓名"
        v-model="queryForm.realName"
      >
      </el-input>
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="请输入手机号"
        v-model="queryForm.phone"
      >
      </el-input>
      <el-input
        style="width: 200px;"
        class="filter-item"
        placeholder="请输入身份证"
        v-model="queryForm.idcard"
      >
      </el-input>
      <el-button
        class="filter-item"
        @click="doSearchQuery"
        type="primary"
        icon="el-icon-search"
        title="搜索"
        >搜索</el-button
      >
    </div>
    <el-table
      v-loading="loading"
      @sort-change="handleSortChange"
      :data="records"
      style="width: 100%"
    >
      <el-table-column prop="rowId" label="ID" width="100" align="center">
      </el-table-column>
      <el-table-column align="center" label="省/市/区" width="450">
        <template slot-scope="scope">
          {{
            `${scope.row.provinceName}/${scope.row.cityName}/${scope.row.districtName}`
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="communityName"
        label="小区"
        width="250"
      >
      </el-table-column>
      <el-table-column align="center" label="大楼/单元/室" width="250">
        <template slot-scope="scope">
          {{
            `${scope.row.buildName}栋/${scope.row.unitName}单元/${scope.row.number}室`
          }}
        </template>
      </el-table-column>
      <el-table-column align="center" prop="realName" label="姓名" width="150">
      </el-table-column>
      <el-table-column align="center" prop="phone" label="电话" width="250">
        <template slot-scope="scope">
          <template v-if="scope.row.phone !== undefined">
            {{
              scope.row.phone.substr(0, 3) + '*****' + scope.row.phone.slice(8)
            }}
          </template>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="idcard" label="身份证" width="250">
        <template slot-scope="scope">
          <template
            v-if="
              scope.row.idcard !== undefined && scope.row.idcard.length == 15
            "
          >
            {{
              scope.row.idcard.substr(0, 4) +
                '******' +
                scope.row.idcard.slice(11)
            }}
          </template>
          <template
            v-if="
              scope.row.idcard !== undefined && scope.row.idcard.length == 18
            "
          >
            {{
              scope.row.idcard.substr(0, 4) +
                '******' +
                scope.row.idcard.slice(14)
            }}
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="relationType"
        label="住户类型"
        width="150"
      >
        <template slot-scope="scope">
          {{ Dicts.HOUSE_USER_RELATION_TYPE[scope.row.relationType] }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="modifyName"
        label="操作人"
        width="150"
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="modifyTime"
        label="操作时间"
        width="250"
      >
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryForm.current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="queryForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="queryForm.total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { queryResidentByPage } from '@/api/community'
export default {
  name: 'history',
  data() {
    return {
      loading: false,
      queryForm: {
        current: 1,
        pages: 0,
        total: 0,
        size: 10,
        ascs: '',
        descs: '',
        importance: undefined,
        title: undefined
      },
      statusOptions: Dicts.RESIDENT_IS_ADMIN,
      records: []
    }
  },
  created() {
    this.doQuery()
  },
  methods: {
    handleSortChange({ column, prop, order }) {
      this.queryForm.ascs = ''
      this.queryForm.descs = ''
      if (order) {
        if (order === 'ascending') {
          this.queryForm.ascs = column.sortBy
        } else {
          this.queryForm.descs = column.sortBy
        }
      }
      this.queryForm.current = 0
      this.doQuery()
    },
    handleCurrentChange(current) {
      this.queryForm.current = current
      this.doQuery()
    },
    handleSizeChange(size) {
      this.queryForm.size = size
      this.doQuery()
    },
    doSearchQuery() {
      this.queryForm.current = 1
      this.doQuery()
    },
    doQuery() {
      this.loading = true
      this.queryForm.isDeleted = 1
      queryResidentByPage(this.queryForm).then(({ data: { data } }) => {
        this.queryForm.current = data.current
        this.queryForm.pages = data.pages
        this.queryForm.total = data.total
        this.queryForm.size = data.size
        this.records = data.records
        this.loading = false
      })
    }
  },
  components: {}
}
</script>

<style scoped></style>
